from ConfigParser import RawConfigParser as ConfigParser

from twisted.internet.protocol import Factory

from pankakes import logger
from pankakes.logger import log
from pankakes.protocol import PankakeProtocol

class PankakeFactory(Factory):
	protocol = PankakeProtocol
	
	def __init__(self):
		self.rooms = {}
		self.clients = {}
		self.max_clients = 10
		settings = ConfigParser()
		settings.read('config.ini')
		self.default_room = settings.get('default','room')
		self.rooms[self.default_room] = [0]
		self.default_nick = settings.get('default','nickname')
		self.welcome_message = settings.get('default','message')
		
	def claimId(self,client):
		for i in range(1, self.max_clients+1):
			if i not in self.clients:
				self.clients[i] = client
				return i
		raise ServerFull
		
	def releaseId(self,id):
		del self.clients[id]